import java.util.ArrayList;
import java.util.Date;

import myfirstgrailsproject.Course;
import myfirstgrailsproject.Enrollment;
import myfirstgrailsproject.Exercise;
import myfirstgrailsproject.Exercise.TeamType;
import myfirstgrailsproject.Team;
import myfirstgrailsproject.User;
import myfirstgrailsproject.User.UserType;

import grails.util.GrailsUtil;

/**
 * Here, we create a data that will be loaded at startup
 * 
 * @author zach
 */
class BootStrap {
	def init = { servletContext ->		
		/**
		 * Let test mode populate the database with bootstrap data but don't reload
		 * for production mode (if I delete an object created below in production mode, 
		 * I don't want it to come back the next time I run the app in production mode).
		 */
		if(GrailsUtil.environment == "production") { return }
		
			new User(email:"admin@hogwarts.edu", password:"admin", 
				username:"admin", firstName:"Albus", lastName:"Dumbledore", 
				loginAttempts:0, userType:UserType.ADMIN, 
				locked:false).save();
			new User(email:"instructor@theshire.edu", password:"instructor",
				username:"instructor", firstName:"Bilbo", lastName:"Baggins",
				loginAttempts:0, userType:UserType.INSTRUCTOR,
				locked:false).save();
			new User(email:"student@battleschool.edu", password:"student",
				username:"student", firstName:"Ender", lastName:"Wiggin",
				loginAttempts:0, userType:UserType.STUDENT,
				locked:false).save();
			new User(email:"student@battleschool.edu", password:"student",
				username:"student", firstName:"Ender", lastName:"Wiggin",
				loginAttempts:0, userType:UserType.STUDENT,
				locked:false).save();
			new User(email:"zwilt3@gatech.edu", password:"zwilt3",
				username:"zwilt3", firstName:"Zach", lastName:"Wilt",
				loginAttempts:0, userType:UserType.STUDENT,
				locked:false).save();
			new User(email:"aclegg@gatech.edu", password:"alex",
				username:"alex", firstName:"Alex", lastName:"Clegg",
				loginAttempts:0, userType:UserType.STUDENT,
				locked:false).save();
			new User(email:"lsissoko@gatech.edu", password:"lamine",
				username:"lamine", firstName:"Lamine", lastName:"Sissoko",
				loginAttempts:0, userType:UserType.STUDENT,
				locked:false).save();
			new User(email:"sbuckner@gatech.edu", password:"simon",
				username:"simon", firstName:"Simon", lastName:"Buckner",
				loginAttempts:0, userType:UserType.STUDENT,
				locked:false).save();
			new User(email:"waters@gatech.edu", password:"waters",
				username:"waters", firstName:"Bob", lastName:"Waters",
				loginAttempts:0, userType:UserType.INSTRUCTOR,
				locked:false).save();
			new User(email:"ulmer@gatech.edu", password:"ulmer",
				username:"ulmer", firstName:"Doug", lastName:"Ulmer",
				loginAttempts:0, userType:UserType.ADMIN,
				locked:false).save();
			new User(email:"leahy@gatech.edu", password:"leahy",
				username:"leahy", firstName:"Bill", lastName:"Leahy",
				loginAttempts:0, userType:UserType.INSTRUCTOR,
				locked:false).save();
			new User(email:"gandalf@gatech.edu", password:"gandalf",
				username:"gandalf", firstName:"Gandalf", lastName:"The Grey",
				loginAttempts:0, userType:UserType.ADMIN,
				locked:false).save();
			new User(email:"tbombadil3@gatech.edu", password:"tbombadil3",
				username:"tbombadil3", firstName:"Tom", lastName:"Bombadil",
				loginAttempts:0, userType:UserType.INSTRUCTOR,
				locked:false).save();
			
			
			new Course(title:"CS 2340", professor:User.findByUsername("waters")).save();
			new Course(title:"CS 2200", professor:User.findByUsername("leahy")).save();
			new Course(title:"MATH 4317", professor:User.findByUsername("ulmer")).save();
			new Course(title:"MATH 4107", professor:User.findByUsername("admin")).save();
			new Course(title:"CS 1332", professor:User.findByUsername("instructor")).save();
			new Course(title:"CS 4400", professor:User.findByUsername("instructor")).save();
			
			
			new Enrollment(user:User.findByUsername("student"), course:Course.findByTitle("CS 2340")).save();
			new Enrollment(user:User.findByUsername("student"), course:Course.findByTitle("CS 2200")).save();
			new Enrollment(user:User.findByUsername("student"), course:Course.findByTitle("MATH 4107")).save();
			new Enrollment(user:User.findByUsername("instructor"), course:Course.findByTitle("CS 2340")).save();
			new Enrollment(user:User.findByUsername("admin"), course:Course.findByTitle("CS 1332")).save();
			new Enrollment(user:User.findByUsername("admin"), course:Course.findByTitle("CS 2340")).save();
			new Enrollment(user:User.findByUsername("lamine"), course:Course.findByTitle("CS 2340")).save();
			new Enrollment(user:User.findByUsername("alex"), course:Course.findByTitle("CS 2340")).save();
			new Enrollment(user:User.findByUsername("simon"), course:Course.findByTitle("CS 2340")).save();
			new Enrollment(user:User.findByUsername("zwilt3"), course:Course.findByTitle("CS 2340")).save();
			new Enrollment(user:User.findByUsername("ulmer"), course:Course.findByTitle("CS 2340")).save();
			
			
	}
	def destroy = {
	}
}
	